import type { REPORT_ID } from '@/enum'
import { queryReportSummaryList, exportFileOfReportSummary } from '@/api/modules/dataReport'

export interface ListItem {
  reportId: REPORT_ID
  reportName: string
}

export interface QueryListParams {
  time: string
}

export function useLoadData() {
  const tableData = ref<ListItem[]>([])
  const loading = ref(false)

  async function queryList(params: QueryListParams) {
    loading.value = true
    let data = [] as ListItem[]
    try {
      const { data: res } = await queryReportSummaryList(params.time)
      tableData.value = res.dataList ?? []
      data = res.dataList ?? []
    }
    finally {
      loading.value = false
    }
    return data
  }

  async function exportFile(time: string, reportId: REPORT_ID) {
    await exportFileOfReportSummary(time, reportId)
  }

  return {
    loading,
    tableData,
    queryList,
    exportFile,
  }
}
